<?php

namespace App\Http\Controllers\home;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
class ResumeController extends Controller
{
    public function getFirst()
    {

        if(!empty(session('data')))
        {
            session(['user'=>session('data')]);
        }
        $da=DB::table('interviewee')->select('id')->where('phone',session('user')['phone'])->first();
        // dd($da->id);
        session(["user.id"=>$da->id]);


      
        $data=session('user');
    	$re=DB::table('regioncate')->where('status',1)->take(28)->get();
    	$sheng=DB::table('regioncate')->where('pid',0)->where('status',0)->get();
    	return view('home/resume/add',['re'=>$re,'sheng'=>$sheng,'data'=>$data]);
    }
    public function postAjaxsheng(Request $request)
    {
    	// dd($request->id);
    	$data=DB::table('regioncate')->where('pid',$request->id)->get();
    	return response()->json($data);	
    }
    public function postSecond(Request $request)
    {
        $data=[];
        $data['name']=$request['username'];
        $data['sex']=$request['gender'];
        $data['birthday']=$request['birth_date_y'].$request['birth_date_m'];
        $data['wy']=$request['experience'].$request['experience_month'];
        $data['here']=$request['hukou_p'];
        $data['city']=$request['residence_p'];
        $data['id_card']=$request['id_number'];
        $data['card_cate']=$request['id_type'];
        $data['email']=$request['emailshow'];
        $res=DB::table('interviewee')->where('phone',session('user')['phone'])->update($data);
        if($res)
        {
             $re=DB::table('regioncate')->where('status',1)->take(28)->get();
             $sheng=DB::table('regioncate')->where('pid',0)->where('status',0)->get();
             // 职位表
             $tou=DB::table('industrycate')->where('pid',0)->get();
             
             foreach($tou as $k=>$v)
             {
               $erji[$k]=DB::table('industrycate')->where('pid',$v->id)->get();
             }
             //工资
             $salary=DB::table('pms')->get();
             //从事职业
             $zong=DB::table('cate')->where('pid',0)->get();
             foreach($zong as $k=>$v)
             {
                //计算高度
                $zong[$k]->length=DB::table('cate')->where('pid',$v->id)->count()*30.86;
             }
             
             $er=DB::table('cate')->where('pid','>',0)->where('pid','<',14)->get();

             $enducate=DB::table('er')->get();

             $status=DB::table('resume_status')->get();
    


             return view('home/resume/second',['re'=>$re,'sheng'=>$sheng,'tou'=>$tou,'erji'=>$erji,'salary'=>$salary ,'zong'=>$zong,'er'=>$er,'enducate'=>$enducate,'status'=>$status]);

        }else
        {
            return back();
        }
      
       

        
    }

    public function postAjaxwork(Request $request)
    {
        $data=DB::table('cate')->where('pid',$request->id)->get();
        return response()->json($data);
    }

    public function postResume(Request $request)
    {

        // dd($request->all());
        $data=$request->except('_token','Language','JobType','SubJobType','MajorSubType','desired_Industry_super','desired_Jobtype','industry_sub','DesiredJobType');
        // dd(session('user'));
        $data['inter_id']=session('user')['id'];
        $data['time']=time();
        $r=DB::table('resume')->where('inter_id',session('user')['id'])->first();
        if($r)
        {
            $res=DB::table('resume')->where('inter_id',session('user')['id'])->update($data);
            return view('/home/resume/third');

        }


        $res=DB::table('resume')->insert($data);
        if($res)
        {
            return view('/home/resume/third');
        }else
        {
            return back();
        }
    }



}
